package com.kaiwukj.android.ufamily.mvp.ui.page.service.fee;

import android.os.Bundle;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ToastUtils;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.app.base.review.BaseActivity;
import com.kaiwukj.android.ufamily.app.constant.ARouterUrlKt;
import com.kaiwukj.android.ufamily.mvp.http.entity.bean.PayFeeHistoryDetailBean;
import com.kaiwukj.android.ufamily.mvp.http.entity.resultbak.PayFeeResult;
import com.kaiwukj.android.ufamily.mvp.ui.adapter.PayFeeHistoryDetailAdapter;
import com.kaiwukj.android.ufamily.mvp.ui.widget.PayFeeItemDecoration;
import com.qmuiteam.qmui.widget.QMUITopBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2019/10/25
 */
@Route(path = ARouterUrlKt.PayFeeHistoryDetail)
public class PayFeeHistoryDetailActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    QMUITopBar topBar;
    @BindView(R.id.tv_message)
    TextView tvMessage;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.recycler)
    RecyclerView recyclerView;

    @Autowired
    PayFeeResult result;

    private int type;
    private String noName = "楼宇/单元/房号";

    @Override
    protected int getLayoutId() {
        ARouter.getInstance().inject(this);
        return R.layout.activity_payfee_history_detail;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        topBar.setTitle("详情");
        topBar.addLeftBackImageButton().setOnClickListener(v -> onBackPressedSupport());

        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new PayFeeItemDecoration());

        if (result == null) {
            ToastUtils.showShort("数据异常");
            return;
        }

        type = result.getType();
        switch (type) {
            case 1:
                topBar.setTitle("物业费详情");
                tvMessage.setText("您好，您已成功缴纳物业费");
                noName = "楼宇/单元/房号";
                break;
            case 2:
                topBar.setTitle("车位费详情");
                tvMessage.setText("您好，您已成功缴纳车位费");
                noName = "车位号";
                break;
            default:
                topBar.setTitle("未知");
                break;
        }
    }

    @Override
    protected void initData(Bundle savedInstanceState) {

        tvMoney.setText(String.valueOf(result.getPaymentAmount()));

        List<PayFeeHistoryDetailBean> items = new ArrayList<>();
        items.add(new PayFeeHistoryDetailBean(PayFeeHistoryDetailBean.PERSON, "缴费人", result.getOwnerName()));
        items.add(new PayFeeHistoryDetailBean(PayFeeHistoryDetailBean.PHONE, "手机号", result.getOwnerPhone()));
        items.add(new PayFeeHistoryDetailBean(PayFeeHistoryDetailBean.HOUSE, noName, result.getReferenceNo()));
        items.add(new PayFeeHistoryDetailBean(PayFeeHistoryDetailBean.ADDRESS, "物业地址", result.getCommunityName()));

        items.add(new PayFeeHistoryDetailBean(PayFeeHistoryDetailBean.CREATE_TIME, "账单生成日期",
                result.getCreateTime()));
        items.add(new PayFeeHistoryDetailBean(PayFeeHistoryDetailBean.ORDER_MONEY, "应缴金额",
                String.valueOf(result.getPayableAmount())));
        items.add(new PayFeeHistoryDetailBean(PayFeeHistoryDetailBean.PAY_MONEY, "实缴金额",
                String.valueOf(result.getPaymentAmount())));
        items.add(new PayFeeHistoryDetailBean(PayFeeHistoryDetailBean.PAY_WAY,
                "支付方式", result.getPayTypeName()));
        items.add(new PayFeeHistoryDetailBean(PayFeeHistoryDetailBean.PAY_TIME, "缴纳时间",
                result.getPayTime()));


        PayFeeHistoryDetailAdapter mAdapter = new PayFeeHistoryDetailAdapter(items);
        recyclerView.setAdapter(mAdapter);
    }

}
